﻿using System.Collections;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace SpaceBattle.Model
{
    public static class Input
    {
        private static KeyboardState _keyboardState;
        private static KeyboardState _lastKeyboardState;
        private static MouseState _mouseState;
        private static MouseState _lastMouseState;

        public static void Update(GameTime gameTime)
        {
            _lastKeyboardState = _keyboardState;
            _keyboardState = Keyboard.GetState();

            _lastMouseState = _mouseState;
            _mouseState = Mouse.GetState();
        }

        //CZY KLAWISZ ZOSTAŁ WCIŚNIĘTY W MOMENCIE SPRAWDZANIA
        public static bool IsKeyPressed(Keys key)
        {
            return (_keyboardState.IsKeyDown(key) &&
                    _lastKeyboardState.IsKeyUp(key));
        }

        //CZY KLAWISZ JEST WCIŚNIĘTY
        public static bool IsKeyDown(Keys key)
        {
            return (_keyboardState.IsKeyDown(key));
        }

        //CZY KLAWISZ JEST NIE WCIŚNIĘTY
        public static bool IsKeyUp(Keys key)
        {
            return (_keyboardState.IsKeyUp(key));
        }

        //LISTA WCIŚNIĘTYCH KLAWISZY
        public static ArrayList PressedKeys()
        {
            ArrayList keysArray = new ArrayList();
            keysArray.Clear();

            foreach (Keys key in _keyboardState.GetPressedKeys())
                keysArray.Add(key);
            return (keysArray);
        }

        //CZY LEWY KLAWISZ MYSZKI JEST WCIŚNIĘTY W MOMENCIE SPRAWDZANIA
        public static bool IsMouseLeftPressed()
        {
            return (_mouseState.LeftButton == ButtonState.Pressed &&
                       _lastMouseState.LeftButton == ButtonState.Released);
        }

        //CZY PRAWY KLAWISZ MYSZKI JEST WCIŚNIĘTY W MOMENCIE SPRAWDZANIA
        public static bool IsMouseRightPressed()
        {
            return (_mouseState.RightButton == ButtonState.Pressed &&
                       _lastMouseState.RightButton == ButtonState.Released);
        }

        //CZY LEWY KLAWISZ MYSZKI JEST WCIŚNIĘTY
        public static bool IsMouseLeftDown()
        {
            return (_mouseState.LeftButton == ButtonState.Pressed);
        }

        //CZY PRAWY KLAWISZ MYSZKI JEST WCIŚNIĘTY
        public static bool IsMouseRightDown()
        {
            return (_mouseState.RightButton == ButtonState.Pressed);
        }
    }
}
